home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / gltron / texture.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-09  |  1.9 KB  |  63 lines  |  [TEXT/CWIE]

  1. #include "gltron.h"
  2.  
  3. void initTexture(gDisplay *d) {
  4.   GLint min_filter;
  5.   char texname[120];
  6.   int i, j;
  7.   char fallback[] = "default";
  8.   char *path;
  9.  
  10.   if(game->settings->use_mipmaps) {
  11.     if(game->settings->mipmap_filter == TRILINEAR)
  12.       min_filter = GL_LINEAR_MIPMAP_LINEAR;
  13.     else
  14.       min_filter = GL_LINEAR_MIPMAP_NEAREST;
  15.   } else
  16.     min_filter = GL_LINEAR;
  17.  
  18.   checkGLError("texture.c initTexture - start");
  19.   /* todo: move that somewhere else */
  20.   glGenTextures(game_textures, d->textures);
  21.   checkGLError("texture.c initTexture - creating textures");
  22.   for(i = 0; i < n_textures; i++) {
  23.     for( j = 0; j < textures[i].count; j++) {
  24.       glBindTexture(GL_TEXTURE_2D, d->textures[ textures[i].id + j ]);
  25.       /* todo: snprintf would be safer, but win32 doesn't have it */
  26.       if(textures[i].count == 1) {
  27.     sprintf(texname, "%s%c%s%s", 
  28.         d->artpack.path, SEPERATOR, textures[i].name, TEX_SUFFIX);
  29.     if((path = getFullPath(texname)) == NULL) {
  30.       sprintf(texname, "%s%c%s%s", 
  31.           fallback, SEPERATOR, textures[i].name, TEX_SUFFIX);
  32.     } else {
  33.       free(path);
  34.     }
  35.       } else {
  36.     sprintf(texname, "%s%c%s%d%s", 
  37.         d->artpack.path, SEPERATOR, textures[i].name, j, TEX_SUFFIX);
  38.     if((path = getFullPath(texname)) == NULL) {
  39.       sprintf(texname, "%s%c%s%d%s", 
  40.           fallback, SEPERATOR, textures[i].name, j, TEX_SUFFIX);
  41.     } else {
  42.       free(path);
  43.     }
  44.       }
  45.       loadTexture(texname, textures[i].type);
  46.  
  47.       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  48.       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
  49.       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, textures[i].wrap_s);
  50.       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, textures[i].wrap_t);
  51.  
  52.       checkGLError("texture.c initTextures");
  53.     }
  54.   }
  55. }
  56.  
  57. void deleteTextures(gDisplay *d) {
  58.   glDeleteTextures(game_textures, d->textures);
  59.   ogl_debugtex = 0;
  60.  
  61.   checkGLError("texture.c deleted textures");
  62. }
  63.